// pages/advice/advice.js
import http from "../../utils/http.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    maxLen: 200,
    currentLen: 0,
    telNo: '',
    advice: '',
    inputHei: 80,
    show: false,
    showCancel: false

  },

  adviceInput(event) {
    let value = event.detail.value,
      len = parseInt(value.length);
    let that = this;
    this.setData({
      currentLen: len,
      advice: value
    });
  },
  telInput(event) {
    let value = event.detail.value;
    let that = this;
    this.setData({
      telNo: value
    });

  },
  commitAdvice() {
    let that = this;
    let advice = that.data.advice;
    let tel = that.data.telNo;
    // console.log(advice)
    // console.log(tel)
    if(advice ==''){
      wx.showToast({
        title: '请输入您的意见或者建议',
        icon: "none",
        duration: 2000
      })
      return;
    }
    if (tel == '' || tel == null || tel ==undefined){
      //提交数据
      http.request({
        url: '/feedback/addFeedback',
        data: {
          tel: tel,
          content: advice
        },
        success: (result) => {
          that.setData({
            show: true
          })
        }
      });
    }else{

      let flag = that.isPoneAvailable(tel);
      if (flag) {
        //提交数据
        http.request({
          url: '/feedback/addFeedback',
          data: {
            tel: tel,
            content: advice
          },
          success: (result) => {
            that.setData({
              show: true
            })
          }
        });
      } else {
        wx.showToast({
          title: '请输入正确的手机号',
          icon: "none",
          duration: 2000
        })
      }
    }

    
  },
  handleOK: function() {
    this.setData({
      telNo: '',
      advice: '',
      show: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
  },
  isPoneAvailable: function(telno) {
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if (!myreg.test(telno)) {

      return false;
    } else {
      return true;
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})